package main;

import controller.CheckController;
import service.Calculate;
import service.CalculateImpl;
import service.Expression;
import service.ExpressionImpl;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main3 {
    public static void main(String[] args) {
//        //生成指定数目的算是表达式
        System.out.println("请使用 -n 参数控制生成题目的个数，使用 -r 参数控制题目中数值（自然数、真分数和真分数分母）的范围：");
        Scanner sc=new Scanner(System.in);
        String str=sc.nextLine();
        Pattern pattern = Pattern.compile("\\d+");
        Matcher matcher = pattern.matcher(str);
        String[] a={"",""};
        int i=0;
        while (matcher.find()) {
            a[i] = matcher.group();
            i++;
        }
        Expression expression = new ExpressionImpl();
        Calculate calculate = new CalculateImpl();
        String answerTemp;
        List<String> expression1 = expression.createExpression(Integer.valueOf(a[0]), Integer.valueOf(a[1]));
        List<String> answerList = new ArrayList<>();
        expression.writeToFile("Exercises.txt");
        for (String s : expression1) {
            answerTemp = "";
            String result = calculate.calculate(s);
            answerTemp = s + " = " + result;
            System.out.println(answerTemp);
            answerList.add(answerTemp);
        }
        expression.answerToFile(answerList, "Answers.txt");
        //对给定的题目文件和答案文件，判定答案中的对错并进行数量统计
        System.out.println("给定题目文件和答案文件（如-e <exercises.txt> -a <answers.txt>：");
        String file=sc.nextLine();
        String[] b={"",""};
        int j=0;
        int e = file.indexOf("<");
        int e3 = file.indexOf(">");
        int e1 = file.lastIndexOf("<");
        int e2 = file.lastIndexOf(">");
        b[0]=file.substring(e+1,e3);
        b[1]=file.substring(e1+1,e2);
        System.out.println(b[0]);
        System.out.println(b[1]);
        CheckController checkController = new CheckController();
        checkController.checkPaper(b[0],b[1]);
    }
}
